package client.control;



/**
  * @Description 一个网络返回值实体类,同一个包内可写,其他地方只可读
  * @author 孔明浩
  * @Date 2020/4/8
  */
public class ResponseEntity {
    //返回值代码
    int code = -1;
    //出错时的出错信息
    String message = "";
    //未出错时的返回data
    String data = "";
    /**
     * @Description 装填connectControl获取的数据到数据类中
     * @author 孔明浩
     * @Date 2020/4/7
     */
    static ResponseEntity fit(ConnectControl connectControl){
        return new ResponseEntity(connectControl.code, connectControl.message,connectControl.data);
    }

    /**
      * @Description 默认构造函数
      * @author 孔明浩
      * @Date 2020/4/8
      */
    public ResponseEntity(){}

    protected ResponseEntity(int code, String message, String data){
        this.code = code;
        this.message = message;
        this.data = data;
    };

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public String getData() {
        return data;
    }

    @Override
    public String toString() {
        return "ResponseEntity{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data='" + data + '\'' +
                '}';
    }

    /**
      * @Description 把Data当作int类型填入
      * @return 转化为Json类型后的字符串
      * @author 孔明浩
      * @Date 2020/4/12
      */
    protected String toIntJsonString(){
        return "{" +
                "\"code\":" + code +
                ", \"message\":\"" + message + '\"' +
                ", \"data\":" + data +
                '}';
    }
}
